import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/font/iconfont.css'
import Axios from 'axios'


Vue.use(ElementUI);
import { Loading } from 'element-ui';
Axios.defaults.baseURL = "http://121.41.51.231:5000/api/private/v1/"
// axios拦截器
// 发请求之前触发
axios.interceptors.request.use(config=>{
  // console.log("请求之前",config);
  config.headers.Authorization = sessionStorage.getItem("token");
  // 设置等待框
  Loading.service();

  return config;
});
// 发请求之后触发
axios.interceptors.response.use(config=>{
  // console.log("请求之后",config);
  Loading.service().close();
  // 只有token失效才会跳转登录页去
  if (config.data.meta.status == 401) {
    router.push("/login")
  }
  return config;
});
Vue.prototype.axios = Axios;

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
